#!/usr/bin/env @PERL@
# -*- cperl -*-

# %CopyrightBegin%
#
# SPDX-License-Identifier: Apache-2.0
#
# Copyright Ericsson AB 2025. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# %CopyrightEnd%

use strict;

my $key;
my @opts;
my @modules;
my $m;
my $o;

foreach (@ARGV) {
  if (/^\-I(.+)/) {
    push(@opts,"{i,\"$1\"}");
    $key=0;
  }
  elsif (/^\-o(.+)/) {
    push(@opts,"{outdir,\"$1\"}");
    $key=0;
  }
  elsif (/^\-D(.+)=(.+)/) {
    push(@opts,"{d,\'$1\',$2}");
    $key=0;
  }
  elsif (/^\-D(.+)/) {
    push(@opts,"{d,\'$1\'}");
    $key=0;
  }
  elsif (/^\+(.+)/) {
    push(@opts,$1),
    $key=0;
  }
  elsif (/^(\-(.+))$/) {
    $key = $1;
  }
  elsif ($key eq "\-I") {
    push(@opts,"{i,\"$_\"}");
    $key=0;
  }
  elsif ($key eq "\-o") {
    push(@opts,"{outdir,\"$_\"}");
    $key=0;
  }
  elsif ($key) {
    print "Warning: Ignoring invalid option \"$key $_\"\n";
    $key=0;
  }
  else {
    push(@modules,"\'$_\'"),
    $key=0;
  }
};

$m = pop(@modules);
print "{[$m";
foreach (@modules) {
  print ",$_";
};

$o = pop(@opts);
print "],[$o";
foreach (@opts) {
  print ",$_";
};

print "]}.\n";
